package com.flysky.common;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
	
	/**
	 * change a byte[] to strong
	 * @param array
	 * @return
	 */
    public static String hex(byte[] array)  {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < array.length; ++i) {
            sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString();
    }
 
    
    /**
     * encode a message using md5
     * @param message
     * @return
     */
    public static String md5Hex(String message) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            return hex(md.digest(message.getBytes("CP1252")));
        } catch (NoSuchAlgorithmException e) {
 
        } catch (UnsupportedEncodingException e) {
         
        }
        return message;
    }
    
    
    public static void main(String[] args){
    	System.out.println(md5Hex("Pkk@jho1314"));
    }
}
